package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.example.network.*;

public class MainActivity extends Activity {

    private Button buttonText;
    private Button buttonMP3;

    private void initWidget() {

        this.buttonText = (Button) super.findViewById(R.id.buttonText);
        this.buttonMP3 = (Button) super.findViewById(R.id.buttonMP3);
    }

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        this.initWidget();

        this.buttonText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                System.out.println("begin to download...");

                /**
                 * 注意了，127.0.0.1（localhost）并不是直接连本机的tomcat地址，所以一直提示连接拒绝错误，
                 * 该改成：10.0.2.2
                 */

                String result = new FileDownloader().download("http://127.0.0.1:8080/mp3/resource.xml");
//                String result = new FileDownloader().download("http://mobile.pconline.com.cn/dclub/1209/2940968.html");
                System.out.println(result);
            }
        });

    }
}
